package com.binvshe.binvshe.app.home;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.binvshe.binvshe.R;
import com.binvshe.binvshe.app.MainActivity;
import com.binvshe.binvshe.app.storagemanager.SpDao;
import com.pachong.android.baseuicomponent.activity.BaseActivity;

public class SplashActivity extends BaseActivity {

    Handler handler = new Handler();
    private boolean mIsFirstStart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideToolbar();
        mIsFirstStart = SpDao.isFirstTimeStartApp(getBaseContext());
        initActivity();

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
//            window.setNavigationBarColor(Color.TRANSPARENT);
        }

    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.act_splash, null);
    }

    private void initActivity() {

        final Intent intent = new Intent();
        handler.postDelayed(new Runnable() {
            public void run() {
                if (mIsFirstStart) {
                    intent.setClass(SplashActivity.this, GuideActivity.class);
                    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                    SpDao.setKeyFirstTimeStartApp(getBaseContext(), false);
                } else {
                    intent.setClass(SplashActivity.this, MainActivity.class);
                    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                }
                startActivity(intent);
                finish();
            }
        }, 1500);
    }
}
